/**
 * yiqihao(一起好商务股份有限公司) copyright 
 */
package com.p2p.front.dal.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.front.dal.model.UserCredits;

/**
 *
 * @author leiruiqi@yiqihao.com
 *
 * 2015年1月28日 下午1:23:19
 */
public interface UserCreditsDao extends BaseMapper{

	
	@Insert("insert into p2p_user_credits(uid,type,value) values(#{uid},#{type},#{value})")
	public int create(UserCredits userCredists);
		
	@Select("select uid,type,value from p2p_user_credits where uid=#{uid} and type=#{type}")
	public UserCredits getByUserAndType(@Param("uid")String uid,@Param("type")String type);
	
	@Update("update p2p_user_credits set value=value+#{addValue} where uid=#{uid} and type=#{type}")	
	public int addValue(@Param("uid")String uid,@Param("type")String type,@Param("addValue")Long addValue);
	
	@Update("update p2p_user_credits  set value=(case when value<#{subValue} then 0 else value-#{subValue} end) where uid=#{uid} and type=#{type}")	
	public int subValue(@Param("uid")String uid,@Param("type")String type,@Param("subValue")Long subValue);
	
	public List<UserCredits> queryByTypeAndUids(@Param("type")String type,@Param("uidList")List<String> uidList);
	
	@Select("select uid,type,value from p2p_user_credits where type=#{type} order by value desc limit #{top}")
	public List<UserCredits> queryTopByType(@Param("type")String type,@Param("top") Integer top);
}
